<?php
// +---------------------------------------------------------------------+
// | OneBase    | [ WE CAN DO IT JUST THINK ]                            |
// +---------------------------------------------------------------------+
// | Licensed   | http://www.apache.org/licenses/LICENSE-2.0 )           |
// +---------------------------------------------------------------------+
// | Author     | Bigotry <3162875@qq.com>                               |
// +---------------------------------------------------------------------+
// | Repository | https://gitee.com/Bigotry/OneBase                      |
// +---------------------------------------------------------------------+

namespace app\api\controller;

use app\common\model\ChannelWorkClass;
use app\common\model\KingCategory;
use app\common\model\KingDescribe;
use app\common\model\UserLevel;
use think\captcha\Captcha;
use think\Db;

/**
 * 公共基础接口控制器
 */
class Common extends ApiBase
{

    /**
     * 登录接口
     */
    public function login()
    {
        return $this->apiReturn($this->logicCommon->login($this->param));
    }

    /**
     *注册接口
     */
    public function register()
    {
        return $this->apiReturn($this->logicCommon->register($this->param));
    }

    /**
     *验证身份证接口
     */
    public function check_idcard()
    {
        return $this->apiReturn($this->logicCommon->check_idcard($this->param));
    }

    /**
     * H5图片上传
     */
    public function pictureUpload1()
    {
        //dd($_FILES);
        $result = $this->logicFile->pictureUpload();

        return $this->apiReturn($result);
    }
    /**
     * 验证码接口
     */
    public function get_code()
    {
        $config =    [
            // 验证码字体大小
            'fontSize'    =>    30,
            // 验证码位数
            'length'      =>    4,
            // 关闭验证码杂点
            'useNoise'    =>    false,
        ];
        $captcha = new Captcha($config);
       return $captcha->entry( $this->param['code']);
    }

    /**
     * 发送短信接口
     */
    public function send_sms()
    {
        return $this->apiReturn($this->logicCommon->send_sms($this->param));
    }
    /**
     * 发送邮件接口
     */
    public function send_email()
    {
        return $this->apiReturn($this->logicCommon->send_email($this->param));
    }

    /**
     * 发送短信接口
     */
    public function send_sms_new()
    {
        return $this->apiReturn($this->logicCommon->send_sms_new($this->param));
    }

    /**
     * 绑定手机接口
     */
    public function blind_mobile()
    {
        return $this->apiReturn($this->logicCommon->blind_mobile($this->param));
    }

    /**
     * banner接口
     */
    public function getbanner()
    {
        return $this->apiReturn($this->logicCommon->getbanner($this->param));
    }

    /**
     * 图片上传
     */
    public function pictureUpload()
    {

        $result = $this->logicFile->pictureUpload1($this->param);

        return $this->apiReturn($result);
    }


    /***
     * 获取法币支付方式
     */
    public function legal_pay(){
        $arr=[];
        if(getConfig('web_base_alipay_is_open')){
            $alipay['name']=lang('支付宝');
            $alipay['legal']=1;
            $alipay['image']=get_picture_url(getConfig('web_base_alipay_qrcode'),false);
            $arr[]=$alipay;
        }

        if(getConfig('web_base_wechat_is_open')){
            $wechat['name']=lang('微信');
            $wechat['legal']=2;
            $wechat['image']=get_picture_url(getConfig('web_base_wechat_qrcode'),false);
            $arr[]=$wechat;
        }
        return $this->apiReturn($arr);
    }
    /**
     * 获取主流币列表
     */
    public function getEthCurrencyList()
    {
        if(!empty($this->param['id'])){
            $list=\app\common\model\Wallet::get($this->param['id']);
            $list['image']=$list->image;
        }else{
            $list=\app\common\model\Wallet::field('id,name,cover_id,parities,usdt_price,transfer_min,poundage')->where(['status'=>1,'is_currency'=>1,'is_virtual'=>1])->order('id desc')->select();

            foreach ($list as $k=>$v){
                $list[$k]['image']=$v->image;
            }
        }

        return $this->apiReturn($list);
    }
    /**
     * 获取会员等级列表
     */
    public function getLevelList()
    {
        $list=UserLevel::all(['status'=>1]);
        foreach ($list as $k=>$v){
            $list[$k]['image']=$v->image;
            $list[$k]['number']=$v->team_number;
            $share_arr=json_decode($v['share_json'],true);
            if($share_arr){

                if($share_arr[0]['level']==0 ){
                    $list[$k]['share_arr']= [];
                }else{
                    $list[$k]['share_arr']= $share_arr[0];
                }



            }else{
                $list[$k]['share_arr']= [];
            }
        }
        return $this->apiReturn($list);
    }


    /**
     * Game添加
     */
    public function qrcode()
    {


        Vendor('phpqrcode.phpqrcode');
        header("Content-type: image/png");
        ob_end_clean();
        \QRcode::png($this->param['address'],false,QR_ECLEVEL_L,5,2,false,100,1);
        //>>>>>>>直接输出到浏览器>>>>>>>>>>
        //>>>>>>>>>保存文件>>>>>>>>>>>
        //$qrCode->save('ziyuanniao.png'); //保存文件
        //>>>>>>>>>保存文件>>>>>>>>>>>
    }



    /**
     * 修改密码接口
     */
    public function changePassword()
    {

        return $this->apiReturn($this->logicCommon->changePassword($this->param));
    }

    /**
     * 忘记密码接口
     */
    public function forget_pwd()
    {

        return $this->apiReturn($this->logicCommon->forget_pwd($this->param));
    }

    /**
     * 友情链接
     */
    public function getBlogrollList()
    {

        return $this->apiReturn($this->logicCommon->getBlogrollList($this->param));
    }

    /**
     * 第三方平台跳转接口
     */
    public function check_game()
    {

        return $this->apiReturn($this->logicCommon->check_game($this->param));
    }


    /**
     * 第三方详情
     */
    public function game_detail()
    {

        return $this->apiReturn($this->logicCommon->game_detail($this->param));
    }



    /**
     * 货币列表
     */
    public function getCurrencyList()
    {
        $list = \app\common\model\Wallet::all(['status'=>1,'is_virtual'=>0,'is_currency'=>1]);
        foreach ($list as $k=>$v){
            $list[$k]['image']=$v->image;
        }
        return $this->apiReturn($list);
    }
    /**
     * 汇率换算
     */
    public function getNumber()
    {

        $wallet = \app\common\model\Wallet::get($this->param['wallet_id']);
        return $this->apiReturn(format_money($this->param['money']/$wallet['parities'],8));

    }

    /**
     * 订单类型
     */
    public function getOrderType()
    {
        $arr=[
            [
                'id'=>1,
                'name'=>lang('奖励类型'),
                'children'=>[
                    [
                        'id'=>1,
                        'name'=>lang('分享奖'),
                    ],
                    [
                        'id'=>2,
                        'name'=>lang('团队奖'),
                    ],
                    [
                        'id'=>3,
                        'name'=>lang('平级奖'),
                    ],
                    [
                        'id'=>4,
                        'name'=>lang('贡献奖'),
                    ],
                ]
            ],
            [
                'id'=>2,
                'name'=>lang('理财交易类'),
                'children'=>[
                    [
                        'id'=>1,
                        'name'=>lang('交易'),
                    ],
                    [
                        'id'=>2,
                        'name'=>lang('返点'),
                    ],
                    [
                        'id'=>3,
                        'name'=>lang('成功'),
                    ],
                    [
                        'id'=>4,
                        'name'=>lang('失败'),
                    ],
                ]
            ],
            [
                'id'=>3,
                'name'=>lang('钱包类型'),
                'children'=>[
                    // [
                    //     'id'=>1,
                    //     'name'=>lang('转账'),
                    // ],
                    [
                        'id'=>2,
                        'name'=>lang('充值'),
                    ],
                    [
                        'id'=>3,
                        'name'=>lang('划转'),
                    ],
                    [
                        'id'=>4,
                        'name'=>lang('提现'),
                    ],
                    [
                        'id'=>5,
                        'name'=>lang('总包'),
                    ],
                    [
                        'id'=>6,
                        'name'=>'理财包',
                    ],
                ]
            ],
            [
                'id'=>4,
                'name'=>'会员OTC法币交易类型',
                'children'=>[
                    [
                        'id'=>"3",
                        'name'=>'OTC交易',
                    ],
                ]
            ],
            [
                'id'=>7,
                'name'=>'店铺OTC法币交易类型',
                'children'=>[
                    // [
                    //     "id"=>"5",
                    //     "name"=>"全部",
                    // ],
                    [
                        'id'=>1,
                        'name'=>'余额',
                    ],
                    [
                        'id'=>"2",
                        'name'=>'冻结',
                    ],
                    [
                        'id'=>"3",
                        'name'=>'手续费',
                    ],
                   

                    [
                        'id'=>"4",
                        'name'=>'代发',
                    ],
                    [
                        'id'=>"5",
                        'name'=>'代收',
                    ],

                ]
            ],
            [
                'id'=>5,
                'name'=>'交易员类型',
                'children'=>[
                    [
                        'id'=>1,
                        'name'=>'交易员分红',
                    ],
                    [
                        'id'=>"2",
                        'name'=>'委托金额',
                    ],
                ]
            ],
            [
                'id'=>6,
                'name'=>'惩罚类型',
                'children'=>[
                    [
                        'id'=>1,
                        'name'=>'OTC交易违反',
                    ],
//                    [
//                        'id'=>"2",
//                        'name'=>'赌王违反规则',
//                    ],
//                    [
//                        'id'=>"3",
//                        'name'=>'充值违反规则',
//                    ],
                ]
            ],
        ];

        return $this->apiReturn($arr);

    }




    /**
     * 获取汇率
     */
    public function get_rate()
    {

        $wallet = \app\common\model\Wallet::get($this->param['wallet_id']);
        return $this->apiReturn($wallet['parities']);

    }

    /**
     * 置换汇率换算
     */
    public function getEthNumber()
    {
        $wallet = \app\common\model\Wallet::get($this->param['form_wallet_id']);
        $towallet = \app\common\model\Wallet::get($this->param['to_wallet_id']);
        return $this->apiReturn(format_money($this->param['number']*$towallet['parities']/$wallet['parities'],8));
    }


    /**
     * 银行列表
     */
    public function getBankList()
    {

        return $this->apiReturn(get_bank());
    }
    /**
     * 赌王分类列表
     */
    public function getKingCate()
    {
        $list=KingCategory::all(['status'=>1,'parent_id'=>0]);
        foreach ($list as $k=>$v){
            $list[$k]['image']=$v->image;
        }
        return $this->apiReturn($list);
    }

    /**
     * 赌王强项列表
     */
    public function getStrengths()
    {
        $list=KingCategory::all(['parent_id'=>$this->param['id'],'status'=>1]);
//        foreach ($list as $k=>$v){
//            $list[$k]['image']=$v->image;
//        }
        return $this->apiReturn($list);
    }

    /**
     *获取公告
     */
    public function get_notice()
    {

        return $this->apiReturn($this->logicCommon->get_notice($this->param));
    }

    /**
     *获取公告详情
     */
    public function get_notice_info()
    {

        return $this->apiReturn($this->logicCommon->get_notice_info($this->param));
    }

    /**
//     * 获取主流币列表
//     */
//    public function getEthCurrencyList()
//    {
//        $list = Db::name('wallet')->where(['status'=>1,'is_virtual'=>1,'is_currency'=>1])->select();
//        return $this->apiReturn($list);
//    }

    /**
     * 获取虚拟币支付列表
     */
    public function get_currency_pay()
    {
        return $this->apiReturn($this->logicCommon->get_currency_pay());
    }
    /**
     * 获取配置列表
     */
    public function get_config()
    {
        return $this->apiReturn(getConfig());
    }
    /**
     * 获取游戏列表
     */
    public function get_game_list()
    {

        return $this->apiReturn($this->logicCommon->get_game_list());
    }

    /**
     * 获取换算金额
     */
    public function get_conversion()
    {

        return $this->apiReturn($this->logicCommon->get_conversion($this->param));
    }

    /**
     * 获取功能介绍列表
     */
    public function get_version_list()
    {

        return $this->apiReturn($this->logicCommon->get_version_list($this->param));
    }

    /**
     * 获取功能介绍详情
     */
    public function get_version_info()
    {

        return $this->apiReturn($this->logicCommon->get_version_info($this->param));
    }

    /**
     * 获取app更新
     */
    public function get_newest_version()
    {

        return $this->apiReturn($this->logicCommon->get_newest_version());
    }

    /**
     * 币币流水类型
     */
    public function coin_log_type()
    {

        return $this->apiReturn([
            [
              'id'=>14,
              'name'=>lang('充值总包'),
            ],
            [
                'id'=>16,
                'name'=>lang('置换'),
            ],
            [
                'id'=>20,
                'name'=>lang('划转'),
            ],
            [
                'id'=>21,
                'name'=>lang('充币'),
            ],
            [
                'id'=>2,
                'name'=>lang('提币'),
            ],
        ]);
    }

    /***
     * OTC交易价格
     */
    public function otc_prices()
    {
       $arr=getPrice();
        return $this->apiReturn($arr);
    }


    /***
     * 推广海报图片
     */
    public function poster_list(){
        return $this->apiReturn($this->logicCommon->poster_list());
    }


    /**
     * 法币流水类型
     */
    public function legal_currency_log_type()
    {

        return $this->apiReturn([
            [
                'id'=>1,
                'name'=>lang('转入'),
            ],
            [
                'id'=>2,
                'name'=>lang('转出'),
            ],
            [
                'id'=>3,
                'name'=>lang('卖出'),
            ],
            [
                'id'=>2,
                'name'=>lang('买入'),
            ],
        ]);
    }


//    /**
//     * 获取app更新
//     */
//    public function get_about()
//    {
//
//        return $this->apiReturn($this->logicCommon->get_about());
//    }

    /**
     * 扫码得糖果
     */
    public function sweep_code()
    {

        return $this->apiReturn($this->logicCommon->sweep_code($this->param));
    }

    /**
     * 退出
     */
    public function loginout()
    {

        return $this->apiReturn($this->logicCommon->loginout($this->param));
    }


    /**
     * 闪兑交易配置
     */
    public function again_config()
    {

        return $this->apiReturn(Db::name('sys_config')->where(['parent_id' => 5])->column('code,value'));
    }

    /***
     * 工单分类列表
     */

    public function  work_class(){
        $where=['status'=>1];
       !empty($this->param['search_data']) && $where['classname']=['like','%'.$this->param['search_data'].'%'];
        $list= ChannelWorkClass::field('id,classname,cover_id')->where($where)->select();
        foreach ($list as $k=>$v){
            $list[$k]['image']=$v->image;
        }
        return $this->apiReturn($list);
    }


    /**
     * 关于我们
     */
    public function agreement()
    {
        $content=getConfig('about_us');
        if( isset($_REQUEST['lang']) && $_REQUEST['lang']!='zh-cn' &&  $_REQUEST['lang'] ){
            $content=  baidu_translate($content, $_REQUEST['lang']);
        }
        return $this->apiReturn(['content' => $content]);
    }
    /**
     * 赌王心语/赌王履历
     */
    public function king_describe()
    {
        $list= KingDescribe::field('id,name,describe')->where(['status'=>1,'type'=>$this->param['type']])->select();
        return $this->apiReturn($list);
    }


    /**
     * 风险提示
     */
    public function get_about()
    {
        $content=getConfig('agreement');
        if( isset($_REQUEST['lang']) && $_REQUEST['lang']!='zh-cn' &&  $_REQUEST['lang'] ){
            $content=  baidu_translate($content,$_REQUEST['lang']);
        }
        return $this->apiReturn(['content' => $content]);
    }

    /***
     * otc手册协议
     */
    public function  otc_agreement(){
        switch ($this->param['type']){
            case 1:
                $content=getConfig('otc_trade_agreement');
                break;
            case 2:
                $content=getConfig('otc_service_agreement');
                break;
            case 3:
                $content=getConfig('otc_shop_apply_agreement');
                break;
            case 4:
                $content=getConfig('otc_order_release_agreement');
                break;
            case 5:
                $content=getConfig('king_apply_agreement');
                break;
            case 6:
                $content=getConfig('point_agreement');
                break;
        }

        if( isset($_REQUEST['lang']) && $_REQUEST['lang']!='zh-cn' &&  $_REQUEST['lang'] ){
            $content=  baidu_translate($content, $_REQUEST['lang']);
        }
        return $this->apiReturn(['content' => $content]);
    }

    /**
     * 应用分类
     */
    public function game_cate()
    {

        return $this->apiReturn($this->logicCommon->game_cate($this->param));
    }


    /**
     * 根据分类游戏列表接口
     */
    public function get_cate_game()
    {

        return $this->apiReturn($this->logicCommon->get_cate_game($this->param));
    }

    /**
     * 第三方平台同步用户接口
     */
    public function get_user_list()
    {

        return $this->apiReturn($this->logicCommon->get_user_list($this->param));
    }


    /**
     * 第三方平台同步充值接口
     */
    public function get_recharge_list()
    {

        return $this->apiReturn($this->logicCommon->get_recharge_list($this->param));
    }

    /**
     * 第三方平台登录接口接口
     */
    public function get_login()
    {

        return $this->apiReturn($this->logicCommon->get_login($this->param));
    }

    /**
     * 第三方平台交易密码接口
     */
    public function get_trade_pwd()
    {

        return $this->apiReturn($this->logicCommon->get_trade_pwd($this->param));
    }

    /**
     * 获取总包余额接口
     */
    public function get_balance()
    {

        return $this->apiReturn($this->logicCommon->get_balance($this->param));
    }


}
